package cn.com.hongfu.controller;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.hongfu.model.Play;
import cn.com.hongfu.service.PlayService;

@Controller
@RequestMapping("play")
public class PlayController {
	@Autowired
	public PlayService playService ;
	@RequestMapping("add")
	public String add(HttpServletRequest request) throws UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		String playType = request.getParameter("playType");
		String title = request.getParameter("title");
		int playId = Integer.parseInt(request.getParameter("playId"));
		Play play = new Play();
		play.setPlayId(playId);
		play.setTitle(title);
		play.setPlayType(playType);
		play.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		playService.save(play);
		String result = "redirect:/case/list.html";
		if("knowledge".equals(playType))
			result = "redirect:/knowledge/knowledgeList.html";
		return result ;
	}
	@RequestMapping("show")
	public String show(HttpServletRequest request){
		String playType = request.getParameter("playType");
		int playId = Integer.parseInt(request.getParameter("playId"));
		String result ="redirect:/index/caseDesc.html?id="+playId;
		if("knowledge".equals(playType)){
			result ="redirect:/index/knowledgeDesc.html?kId="+playId;
		}
		return result ;
	}
}
